#!../../../common/bats/bin/bats 
# -*-sh-*-

source ../../../common/test_helper_functions.bash || exit 1

if [ -s ./TEST_ENV ];then
    source ./TEST_ENV
fi

CMD_TIMEOUT="10:00"
TEST_NUM_RANKS=8
TEST_NUM_THREADS=4

PKG=IMB
module=imb
family=$LMOD_FAMILY_COMPILER-$LMOD_FAMILY_MPI
rpm=$module-$family${DELIM}

@test "[$PKG] Verify $PKG module is loaded and matches rpm version ($family)" {
    module list $module | grep "1) $module" >& .cmd_output || exit 1
    run grep $module .cmd_output 
    assert_success
    
    # check version against rpm
    local version="$(rpm -q --queryformat='%{VERSION}\n' $rpm)"
    run cat .cmd_output
    assert_output "  1) $module/$version"
}

@test "[$PKG] Verify ${PKG}_DIR is defined and directory exists ($family)" {
    PKG_DIR=${PKG}_DIR

    if [ -z "${!PKG_DIR}" ];then
        flunk "env setting ${PKG_DIR} not defined"
    fi

    if [ ! -d "${!PKG_DIR}" ];then
        flunk "directory ${!PKG_DIR} does not exist"
    fi
}

# ----------
# Bin Tests
# ----------

@test "[$PKG] Verify executables are present in ${PKG}_DIR/bin ($family)" {
    PKG_DIR=${PKG}_DIR

    if [ ! -d "${!PKG_DIR}/bin" ];then
        flunk "directory ${!PKG_DIR}/bin does not exist"
    fi

    for v in IMB-EXT IMB-IO IMB-MPI1 IMB-NBC IMB-RMA
    do
        binaryfile=${!PKG_DIR}/bin/$v
        if [ ! -s "${binaryfile}" ];then
            flunk "${binaryfile} does not exist"
        fi
    done
}

rm -f .cmd_output
